<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>比较运算电路实验 :: 计算机组成原理实验指导</title>
    <meta name="generator" content="Antora 3.2.0-alpha.8">
    <link rel="stylesheet" href="../../../_/css/site.css">
<!--    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> -->
  </head>
  <body class="article">
<header class="header">
  <nav class="navbar">
    <div class="navbar-brand">
      <a class="navbar-item" href="../../..">计算机组成原理实验指导</a>
      <button class="navbar-burger" aria-controls="topbar-nav" aria-expanded="false" aria-label="Toggle main menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </div>
    <div id="topbar-nav" class="navbar-menu">
      <div class="navbar-end">

        <div class="navbar-item">
          <span class="control">
            <a class="button is-primary" href="https://gitee.com/fpga-lab/digisimlab-open" target="_blank">Download</a>
          </span>
        </div>
      </div>
    </div>
  </nav>
</header>
<div class="body">
<div class="nav-container" data-component="digisimlab" data-version="1.0">
  <aside class="nav">
    <div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
  <nav class="nav-menu">
    <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button>
    <h3 class="title"><a href="../index.html">计算机组成原理实验指导</a></h3>
<ul class="nav-list">
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../index.html">前言</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">Digital仿真软件使用指南</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../introduce-digitalsim.html">下载与安装</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-getting-started.html">新手入门</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-generate-circuit.html">电路生成</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-test-circuit.html">电路测试</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-sim-dff.html">时序电路仿真</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-other-useful.html">几个有用的组件</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-hierarchical-design.html">层次化设计</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-parametric-design.html">参数化设计</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">基本逻辑电路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-multiplexer.html">多路选择器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-decoder.html">译码器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-counter.html">计数器实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">运算电路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-add_sub_operation.html">加减运算电路实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-arithmetic_logic_unit.html">算术逻辑单元实验</a>
  </li>
  <li class="nav-item is-current-page" data-depth="2">
    <a class="nav-link" href="op-compare.html">比较运算电路实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">数据通路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-register_file.html">寄存器堆实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-single_cycle_datapath.html">单周期数据通路实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">存储器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="mem-memory.html">存储器实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">控制器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-1.html">硬布线控制实验（Ⅰ）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller.html">硬布线控制实验（Ⅱ）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-3.html">硬布线控制实验（Ⅲ）</a>
  </li>
</ul>
  </li>
</ul>
  </li>
</ul>
  </nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
  <div class="context">
    <span class="title">计算机组成原理实验指导</span>
    <span class="version">1.0</span>
  </div>
  <ul class="components">
    <li class="component is-current">
      <div class="title"><a href="../../index.html">计算机组成原理实验指导</a></div>
      <ul class="versions">
        <li class="version is-latest">
          <a href="../../index.html">1.31</a>
        </li>
        <li class="version">
          <a href="../../1.2/index.html">1.2</a>
        </li>
        <li class="version">
          <a href="../../1.1/index.html">1.1</a>
        </li>
        <li class="version is-current">
          <a href="../index.html">1.0</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
    </div>
  </aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
  <a href="../../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
  <ul>
    <li><a href="../index.html">计算机组成原理实验指导</a></li>
    <li>运算电路</li>
    <li><a href="op-compare.html">比较运算电路实验</a></li>
  </ul>
</nav>
<div class="page-versions">
  <button class="version-menu-toggle" title="Show other versions of page">1.0</button>
  <div class="version-menu">
    <a class="version" href="../../lab/op-compare.html">1.31</a>
    <a class="version" href="../../1.2/lab/op-compare.html">1.2</a>
    <a class="version" href="../../1.1/lab/op-compare.html">1.1</a>
    <a class="version is-current" href="op-compare.html">1.0</a>
  </div>
</div>
</div>
  <div class="content">
<aside class="toc sidebar" data-title="页内目录" data-levels="2">
  <div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page">比较运算电路实验</h1>
<div class="sect1">
<h2 id="_实验目的"><a class="anchor" href="#_实验目的"></a>实验目的</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>理解标志位的含义。</p>
</li>
<li>
<p>掌握比较运算方法。</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验原理"><a class="anchor" href="#_实验原理"></a>实验原理</h2>
<div class="sectionbody">
<div class="paragraph">
<p>在计算机软件程序设计中，常常需要比较两个变量的数值大小。实现两个数大小比较的最直接的做法就是将这两个数相减，根据减法的结果判断两者的大小。例如，若X&lt;Y，则X-Y的结果一定为负，因此依据符号标志就可以判断；但是若运算结果溢出，则恰恰相反。<a href="#tab-3">表 1</a>给出了两个带符号数依据减法运算结果的标志位比较大小的判断条件。而两个无符号数的相减，则可依据是否有借位来判断两个数的大小。<a href="#tab-4">表 2</a>给出了无符号数比较大小的判断条件。</p>
</div>
<table id="tab-3" class="tableblock frame-all grid-all stretch">
<caption class="title">表 1. 两个带符号数比较大小的判定条件</caption>
<colgroup>
<col style="width: 35%;">
<col style="width: 65%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">大小关系</th>
<th class="tableblock halign-left valign-top">判定条件</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X&gt;Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">OF⊕SF=0 且ZF=0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≥Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">OF⊕SF =0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X=Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ZF=1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≠Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ZF=0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X&lt;Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">OF⊕SF =1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≤Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">OF⊕SF =1 或ZF=1</p></td>
</tr>
</tbody>
</table>
<table id="tab-4" class="tableblock frame-all grid-all stretch">
<caption class="title">表 2. 两个无符号数比较大小的判定条件</caption>
<colgroup>
<col style="width: 40%;">
<col style="width: 60%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">大小关系</th>
<th class="tableblock halign-left valign-top">判定条件</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X&gt;Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">BF=0 且ZF=0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≥Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">BF=0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X=Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ZF=1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≠Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ZF=0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X&lt;Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">BF=1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">X≤Y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">BF=1 或ZF=1</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>注：表中BF表示借位，BF=0代表没有借位，BF=1代表有借位。BF可以由进位标志CF得到，根据电路设计的不同，BF可能与CF相反，也可能与CF一致。</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验任务"><a class="anchor" href="#_实验任务"></a>实验任务</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>设计</p>
<div class="paragraph">
<p>依据S、Z、O标志位，产生带符号数相等、不等、小于、大于等于的比较结果。
可使用Digital仿真软件的电路生成功能，输入表达式自动生成电路图，具体用法参考第一章Digital仿真软件使用指南的“<a href="../ds-generate-circuit.html" class="xref page">电路生成</a>”。</p>
</div>
</li>
<li>
<p>仿真</p>
<div class="paragraph">
<p>将比较电路作为子电路添加到ALU实验电路中，并将ALU输出的标志位与比较电路连接。操作ALU做减法运算，输入不同运算数据，验证比较结果是否正确。</p>
</div>
</li>
</ol>
</div>
<div class="sidebarblock text-center">
<div class="content">
<div class="title">许可 | License</div>
<div class="paragraph">
<p><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA：署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></p>
</div>
<div class="paragraph">
<p>作者：
肖铁军 &lt;<a href="mailto:xiaotiejun@foxmail.com.cn">xiaotiejun@foxmail.com.cn</a>&gt;</p>
</div>
</div>
</div>
</div>
</div>
</article>
  </div>
</main>
</div>
<footer class="footer">
  <p>This page was built using the Antora default UI.</p>
  <p>The source code for this UI is licensed under the terms of the MPL-2.0 license.</p>
</footer>
<script id="site-script" src="../../../_/js/site.js" data-ui-root-path="../../../_"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
  </body>
</html>
